package algorithm.poj.p1000;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

/**
 * id: 1008
 * @author wong.tong@gmail.com
 *
 */
public class P1008 {

	public static void main(String[] args) throws Exception {
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

        String line;

        line = stdin.readLine();
        int cnt = Integer.valueOf(line);
        String s = "" + cnt + "\n";
        
        for (int i = 0; i < cnt; i ++) {
        	line = stdin.readLine();
        	s += tzolkin(haab(line)) + "\n";
        }
        System.out.println(s);
	}
	
	private static Map<String, Integer> HAAB_MONTH = new HashMap<String, Integer>();
	private static String[] TZOLKIN_MONTH;
	static {
		String[] ms = {
				"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", 
				"mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", 
				"pax", "koyab", "cumhu", "uayet"
		};
		for (int i = 0; i < ms.length; i ++) {
			HAAB_MONTH.put(ms[i], i);
		}
		
		TZOLKIN_MONTH = new String[]{
				"imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", 
				"lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", 
				"cib", "caban", "eznab", "canac", "ahau"
		};
	}
	
	
	private static int haab(String date) {

		String[] tmp = date.split("\\s+");
		int day = Integer.valueOf(tmp[0].substring(0, tmp[0].length()-1));
		int month = HAAB_MONTH.get(tmp[1]);
		int year = Integer.valueOf(tmp[2]);
		
		return year*365 + month*20 + day;			
	}
	
	private static String tzolkin(int days) {
		
		int year = days/260;
		String month = TZOLKIN_MONTH[days%20];
		int day = days%13 + 1;
		return day + " " + month + " " + year;
	}

}
